<%@page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%
{

WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
UserAction userAction = ActionCreator.createUserAction();

int[] currentTime = Util.getCurrentDate();
int currentMonthEnd = Util.getCurrentMonthEnd();

User user = (User) session.getAttribute(Constants.SESSION_USER);
Role role = userAction.getUserRole(request);
int intRole = writeProblemAction.calRole(null, null, null, role);
String fromPage = request.getParameter(Constants.REQUEST_PARAMETER_FROM_PAGE);
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 填报事故情况登记表
</div>
<div class="tt">《事故情况登记表》</div>
<div class="content">
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" colspan="2" height="35" id="chooseDepartEquipTD">
				<%@include file="/write_problem_depart_equip_section.jsp" %>
				<span style="margin-left: 20px" class="span1">事故类型：</span>
				<span>
					<%@include file="/accident/accident_type_select_section.jsp" %>
				</span>
			</td>
		</tr>
		<tr>
			<td class="td1" width="60%">			
				<span style="margin-left: 30px; font-weight: ">事故名称：</span>  <br/>
				<span style="margin-left: 30px;">
						<textarea rows="3" style="width:90%; margin-bottom:5px;" id="accidentName"></textarea>	
				</span>	
			</td>
			<td  class="td1" width="40%">
				<span style="margin-left: 30px; font-weight: ">事故发生时间：</span>  
				<br/>	
				<span style="margin-left: 30px; ">						
						<select id="startYear" onchange="refreshPeriodStart(true)">
							<%
							for(int i=2001;i<=2050;i++){
							%>
							<option value="<%=i %>" 
								<%
								if(i==currentTime[0]){
								%>
								selected="selected"
								<% 
								}
								%>								
								><%=i %></option>
							<%
							}
							%>
						</select>
						年						
						<select id="startMonth" onchange="refreshPeriodStart(true)">
							<%
							for(int i=1;i<=12;i++){
							%>
							<option value="<%=i %>" 
								<%
								if(i==currentTime[1]){
								%>
								selected="selected"
								<% 
								}
								%>								
								><%=i %></option>
							<%
							}
							%>
						</select>
						月				
						<select id="startDay" onchange="refreshPeriodStart(false)">
							<%
							for(int i=1;i<=currentMonthEnd;i++){
							%>
							<option value="<%=i %>" 
								<%
								if(i==currentTime[2]){
								%>
								selected="selected"
								<% 
								}
								%>								
								><%=i %></option>
							<%
							}
							%>
						</select>
						日		
						<select id="startHour" onchange="refreshPeriodStart(false)">
							<%
							for(int i=0;i<=23;i++){
							%>
							<option value="<%=i %>" 
								<%
								if(i==currentTime[3]){
								%>
								selected="selected"
								<% 
								}
								%>								
								><%=i %></option>
							<%
							}
							%>
						</select>
						时
						<select id="startMinute" onchange="refreshPeriodStart(false)">
							<%
							for(int i=0;i<=59;i++){
							%>
							<option value="<%=i %>" 
								<%
								if(i==currentTime[4]){
								%>
								selected="selected"
								<% 
								}
								%>								
								><%=i %></option>
							<%
							}
							%>
						</select>
						分
				</span>	
			</td>	
		</tr>
		<tr>
			<td class="td1" width="60%">			
				<span style="margin-left: 30px; font-weight: ">人员伤亡情况：</span>  <br/>
				<span style="margin-left: 30px;">
						<textarea rows="3" style="width:90%; margin-bottom:5px;" id="casualty"></textarea>	
				</span>	
			</td>
			<td  class="td1" width="40%">
				<span style="margin-left: 30px; font-weight: ">经济损失初步估计：</span> <br/>
				<span style="margin-left: 30px;">
					<textarea rows="3" style="width:90%; margin-bottom:5px;" id="loss"></textarea>
				</span>	
			</td>	
		</tr>
		<tr>
		<td class="td1" colspan="2">
			<span style="margin-left: 30px; font-weight: ">事故简况：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
				<textarea rows="10" style="width:90%; margin-bottom:5px;"" id="overview"></textarea>	
			</span>
		</td>
		</tr>
		<tr>
		<td class="td1" colspan="2">
			<span style="margin-left: 30px; font-weight: ">事故处置情况说明：
			</span> 
			<br/>
			<span style="margin-left: 30px; ">
				<textarea rows="10" style="width:90%; margin-bottom:5px;"" id="handle"></textarea>	
			</span>
		</td>
		</tr>
		<tr id="informedPersonsTR">
			<td class="td1" colspan="2" height="35">
				<%
				if ((intRole & (Constants.ROLE_TYPE_ZHUANGZHIZHANG)) == 0) {
				%>
				<div id="informPersonDiv">
				<%@include file="/write_problem_informed_person.jsp" %>
				</div>
				<%
				}
				%>
				<div id="chooseManageGroupUserDiv">
				<%@include file="/managegroup_select/manage_check_samepage_section.jsp" %>
				</div>
			</td>
		</tr>
		<tr>
			<td class="td1" colspan="2">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(Calendar.getInstance())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center" colspan="2">
				<input type="button" value="提 交" onclick="writeRegisterform()" />
				<input type="button" value="取 消" style="margin-left: 20px" onclick="cancelWrite()" />
			</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function writeRegisterform(){
	var isSolved = <%=role.getRoleLevel() >= Constants.ROLE_LEVEL_KEJI%>;
	var accidentTypeID = getElementValueByID("accidentType");
	var accidentName = getElementValueByID("accidentName");
	var casualty = getElementValueByID("casualty");
	var loss = getElementValueByID("loss");
	var overview = getElementValueByID("overview");
	var handle = getElementValueByID("handle");
	
	var startYear = $("#startYear").val();
	var startMonth = $("#startMonth").val();
	var startDay = $("#startDay").val();
	var startHour = $("#startHour").val();
	var startMinute = $("#startMinute").val();
	
	if (document.getElementById('equipID') != null) {
		if (getElementValueByID('equipID') == '') {
			$.dialog.alert('请选择发生问题的装置');
			return;
		}
	}

	var userIDs = '';
	var userIDElements = document.getElementsByName('informedUserID');
	for (var i = 0; i != userIDElements.length; i++) {
		var userIDEle = userIDElements[i];
		if (userIDEle.checked) {
			if (userIDs == '') {
				userIDs = userIDs + userIDEle.value;
			} else {
				userIDs = userIDs + ',' + userIDEle.value;
			}
		}
	}
	
	if(accidentTypeID == null || accidentTypeID == '' || accidentTypeID == 'undefined') {
		$.dialog.alert('请选择事故类型');
		return;
	}

	if(overview == null || overview == '' || overview == 'undefined') {
		$.dialog.alert('请填写事故简况');
		return;
	}

	if(handle == null || handle == '' || handle == 'undefined') {
		$.dialog.alert('请填写事故处置情况说明');
		return;
	}
	
	msg = '您确定提交此报告吗？';
	if(isSolved) {
		msg = '是否确认该事故情况登记表?';
	}

	if ($.dialog.confirm(msg, function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'<%=request.getContextPath()%>/accident/write_registerform_process.jsp',
			data:{
				accidentTypeID: accidentTypeID,
				accidentName: accidentName,
				startYear: startYear,
				startMonth: startMonth,
				startDay: startDay,
				startHour: startHour,
				startMinute: startMinute,
				casualty: casualty,
				loss: loss,
				overview: overview,
				handle: handle,

				problemTitle: accidentName,
				problemContent: '',
				zhenggai_cuoshi: '',
				equipID: getElementValueByID('equipID'),
				userID: userIDs,
				depart1ID: getElementValueByID('depart1'),
				isSolved: isSolved
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('报告填报成功！', function() { 
							loadPageSection(
									'<%=request.getContextPath()%>/<%=fromPage%>', 
									'mainContentDiv', 
									{}, 
									true); 
							});
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	}, function(){}));
}
function cancelWrite(){
	loadPageSection('<%=request.getContextPath()%>/<%=fromPage%>', 'mainContentDiv', {}, true);	
}

function refreshPeriodStart(updateMonthEnd){
	var startYear = $("#startYear").val();
	var startMonth = $("#startMonth").val();
	
	if(updateMonthEnd){
		refreshMonthEnd(startYear, startMonth, $("#startDay"));
	}
}

function changeEquip() {
	var equipID = getElementValueByID('equipID');
	loadPageSection('write_problem_informed_person.jsp', 'informPersonDiv', {equipID: equipID}, false);
}

<%
if ((intRole & Constants.ROLE_TYPE_ZUYUAN | Constants.ROLE_TYPE_KEYUAN
		| Constants.ROLE_TYPE_FUKEZHANG | Constants.ROLE_TYPE_KEZHANG | Constants.ROLE_TYPE_FUCHUZHANG
		| Constants.ROLE_TYPE_CHUZHANG | Constants.ROLE_TYPE_ZONGSHI | Constants.ROLE_TYPE_FUZONGJINGLI
		| Constants.ROLE_TYPE_ZONGJINGLI) > 0) {
%>
changeEquip();
<%
}
%>

refreshPeriodStart(false);
</script>
<%
}
%>